package com.example.demo;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:龙宝
 * Date:2023-10-12
 * Time:14:25
 */
@Aspect //切面类
@Component
public class UserAspect {

    @Autowired
    private Task task;

    /**
     * 切点（配置拦截规则）
     */
    @Pointcut("execution(* com.example.demo.controller.UserController.study())")
    public void pointcut() {
    }

    /**
     * 前置通知
     */
    @Before("pointcut()")
    public void beforeAdvice() {
        task.before1();
    }
    /**
     * 后置通知
     */
    @After("pointcut()")
    public void afterAdvice() {
        task.after1();
    }

    @Around("pointcut()")
    public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
        task.around1();
        Object obj = joinPoint.proceed();//执行目标方法
        task.around2();
        return obj;
    }
}
